package com.atguigu.gmall.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
/**
 * ClassName: DelayedMqConfig
 * Package: com.atguigu.gmall.mq.config
 * Description:
 *
 * @Author 刘轩
 * @Create 2023-09-04 20:53
 * @Version 1.0
 */


@Configuration
public class DelayedMqConfig {

 //  声明变量
 public static final String exchange_delay = "exchange.delay";
 public static final String routing_delay = "routing.delay";
 public static final String queue_delay_1 = "queue.delay.1";

 //  声明交换机
 @Bean
 public CustomExchange delayExchange(){
  //  创建map集合
  HashMap<String, Object> map = new HashMap<>();
  map.put("x-delayed-type","direct");
  //  返回交换机
  return new CustomExchange(exchange_delay,"x-delayed-message",true,false,map);
 }

 //  声明队列
 @Bean
 public Queue delayQueue(){
  //  返回队列
  return new Queue(queue_delay_1,true,false,false);
 }

 //  设置绑定关系
 @Bean
 public Binding delayBinding(){
  //  返回绑定关系.
  return BindingBuilder.bind(delayQueue()).to(delayExchange()).with(routing_delay).noargs();
 }

}